package com.qiankun.tang.ui.fragment.follow;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import com.common.library.listener.OnAppListener;
import com.common.library.tools.Logger;
import com.common.library.ui.fragment.BaseRecyclerFragment;
import com.qiankun.tang.R;
import com.qiankun.tang.beans.ADBean;
import com.qiankun.tang.beans.AuthorBean;
import com.qiankun.tang.beans.VideoSynopsisBean;
import com.qiankun.tang.beans.items.FollowItem;
import com.qiankun.tang.ui.activity.PlayerActivity;
import com.qiankun.tang.ui.view.adapter.follow.FollowAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author txf
 * @Title 关注
 * @package com.qiankun.video.ui.fragment
 * @date 2017/6/9 0009
 */
public class FollowFragment extends BaseRecyclerFragment<FollowItem> implements OnAppListener.OnInteractionListener {
    FollowAdapter mFollowAdapter;

    List<String> lurls = new ArrayList<>();
    List<String> ltitles = new ArrayList<>();
    private List<String> xurls = new ArrayList<>();
    private List<String> xtitles= new ArrayList<>();
    private List<String> yurls= new ArrayList<>();
    private List<String> ytitles= new ArrayList<>();

    private void startPlayerActivity(String id) {
        startActivity(PlayerActivity.newIntent(id, getActivity()));
        getActivity().overridePendingTransition(R.anim.activity_zoomin, R.anim.activity_zoomout);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAdapter(mFollowAdapter = new FollowAdapter(getContext(), this));
        initData();
    }
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        getmTitleLayout().setVisibility(View.VISIBLE);
        getmTitle().setText("Follow");
    }
    private void initData() {
        //列表图片数据
        String lurl1 = "res:///" + R.drawable.hom_list_1;
        String lurl2 = "res:///" + R.drawable.hom_list_2;
        String lurl3 = "res:///" + R.drawable.hom_list_3;
        String lurl4 = "res:///" + R.drawable.hom_list_4;
        String lurl5 = "res:///" + R.drawable.hom_list_5;
        String lurl6 = "res:///" + R.drawable.hom_list_6;
        String lurl7 = "res:///" + R.drawable.hom_list_7;
        String lurl8 = "res:///" + R.drawable.hom_list_8;
        String lurl9 = "res:///" + R.drawable.hom_list_9;
        String lurl10 = "res:///" + R.drawable.hom_list_10;
        lurls.add(lurl1);
        lurls.add(lurl2);
        lurls.add(lurl3);
        lurls.add(lurl4);
        lurls.add(lurl5);
        lurls.add(lurl6);
        lurls.add(lurl7);
        lurls.add(lurl8);
        lurls.add(lurl9);
        lurls.add(lurl10);
        String ltitle1 = "宝宝第一次滑雪是什么反应";
        String ltitle2 = "超美沙画作品-大话西游";
        String ltitle3 = "还有叫“嗡”的和弦";
        String ltitle4 = "巨好听！电吉他演绎张国荣经典";
        String ltitle5 = "另类日料，你吃得下吗";
        String ltitle6 = "美女可不是这么追的";
        String ltitle7 = "你躲得开我的凝视吗";
        String ltitle8 = "女神要这样撩";
        String ltitle9 = "悬崖速降，惊心动魄";
        String ltitle10 = "这么懒又这么萌的猫咪我要了";
        ltitles.add(ltitle1);
        ltitles.add(ltitle2);
        ltitles.add(ltitle3);
        ltitles.add(ltitle4);
        ltitles.add(ltitle5);
        ltitles.add(ltitle6);
        ltitles.add(ltitle7);
        ltitles.add(ltitle8);
        ltitles.add(ltitle9);
        ltitles.add(ltitle10);

        //搞笑
        String xuri1 = "res:///" + R.drawable.find_x1;
        String xuri2 = "res:///" + R.drawable.find_x2;
        String xuri3 = "res:///" + R.drawable.find_x3;
        String xuri4 = "res:///" + R.drawable.find_x4;
        String xuri5 = "res:///" + R.drawable.find_x5;
        xurls.add(xuri1);
        xurls.add(xuri2);
        xurls.add(xuri3);
        xurls.add(xuri4);
        xurls.add(xuri5);
        String xtitle1 = "超强音效骗女友";
        String xtitle2 = "大人才能吃的巧克力";
        String xtitle3 = "对不起，我大姨夫来了";
        String xtitle4 = "献给高考生的毒鸡汤";
        String xtitle5 = "这样也算惊喜？！";
        xtitles.add(xtitle1);
        xtitles.add(xtitle2);
        xtitles.add(xtitle3);
        xtitles.add(xtitle4);
        xtitles.add(xtitle5);

        //音乐
        String yuri1 = "res:///" + R.drawable.find_y1;
        String yuri2 = "res:///" + R.drawable.find_y2;
        String yuri3 = "res:///" + R.drawable.find_y3;
        String yuri4 = "res:///" + R.drawable.find_y4;
        String yuri5 = "res:///" + R.drawable.find_y5;
        yurls.add(yuri1);
        yurls.add(yuri2);
        yurls.add(yuri3);
        yurls.add(yuri4);
        yurls.add(yuri5);
        String ytitle1 = "2016电影音乐混剪，听醉了";
        String ytitle2 = "日本宅男神曲《求交往》";
        String ytitle3 = "徐娇二次元#爱之诗#";
        String ytitle4 = "小黄人高能音乐创作";
        String ytitle5 = "男生吉他弹唱《女儿情》";
        ytitles.add(ytitle1);
        ytitles.add(ytitle2);
        ytitles.add(ytitle3);
        ytitles.add(ytitle4);
        ytitles.add(ytitle5);
    }

    @Override
    protected void request(int pageIndex) {
        List<FollowItem> items = buildHomeItems();
        refreshData(items);
    }

    private List<FollowItem> buildHomeItems() {
        List<FollowItem> items = new ArrayList<>();

        //列表图片
        List<VideoSynopsisBean> list1 = new ArrayList<>();
        for (int i = 1; i < 5; i++) {
            VideoSynopsisBean bean = new VideoSynopsisBean();
            bean.setImgUrl(lurls.get(i));
            bean.setSubtitle(ltitles.get(i));
            bean.setTitle(ltitles.get(i));
            list1.add(bean);
        }
        List<VideoSynopsisBean> list2 = new ArrayList<>();
        for (int i = 5; i < 10; i++) {
            VideoSynopsisBean bean = new VideoSynopsisBean();
            bean.setImgUrl(lurls.get(i));
            bean.setSubtitle(ltitles.get(i));
            bean.setTitle(ltitles.get(i));
            list2.add(bean);
        }

        for (int i = 0; i < 3 ; i++) {
            AuthorBean bean = new AuthorBean();
            bean.setId(i+"");
            bean.setIconUrl("res:///" + R.drawable.icon_deft_bg);
            if(i == 0){
                bean.setTitle("搞笑精彩片段");
                bean.setSubtitle("这里是搞笑短片的精选");
                bean.setList(list1);
            }
            if(i == 1){
                bean.setTitle("音乐锦集");
                bean.setSubtitle("聆听新歌热歌的首选");
                bean.setList(list2);
            }
            if(i == 2){
                bean.setTitle("诚实的预告片");
                bean.setSubtitle("[ 诚实的预告片 ] 中文字幕帐号");
                bean.setList(list1);
            }
            items.add(new FollowItem(FollowItem.TYPE_0,bean));
        }

        //分割线
        items.add(new FollowItem(FollowItem.TYPE_LINE, null));

        //viewPager列表
        List<ADBean> adbeans = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ADBean bean = new ADBean();
            bean.setType(0);
            bean.setId(i + "");
            bean.setImgUrl(yurls.get(i));
            bean.setTvtitle(ytitles.get(i));
            bean.setTvsubtitle("TV测试副标题 , " + i);
            bean.setSubtitle("聆听心中的美好");
            bean.setTitle("音乐");
            adbeans.add(bean);
        }
        items.add(new FollowItem(FollowItem.TYPE_1, adbeans));

        //分割线 7dp
        items.add(new FollowItem(FollowItem.TYPE_LINE, null));

        //viewPager列表
        List<ADBean> adbeans2 = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            ADBean bean = new ADBean();
            bean.setType(0);
            bean.setId(i +"");
            bean.setImgUrl(xurls.get(i));
            bean.setTvtitle(xtitles.get(i));
            bean.setTvsubtitle("TV测试副标题 , " + i);
            bean.setSubtitle("精彩只在一瞬间");
            bean.setTitle("搞笑");
            adbeans2.add(bean);
        }
        items.add(new FollowItem(FollowItem.TYPE_1, adbeans2));

        return items;
    }

    @Override
    public void onInteraction(int type, Object o) {
        switch (type) {
            case FollowItem.TYPE_0:
                if (o instanceof ADBean) {
                    Logger.i("点击Item 类型为 0");
                } else {
                    Logger.i("点击搜索按钮 类型为 0");
                }
                startPlayerActivity("0");
                break;
            case FollowItem.TYPE_1:
                if (o instanceof VideoSynopsisBean) {
                    Logger.i("点击Item 类型为 1");
                }
                startPlayerActivity("2");
                break;
        }
    }
}
